package com.cf.game.group;

import com.cf.crud.service.AbsBaseService;
import com.cf.game.group.dao.GroupUserMapper;
import com.cf.game.group.dao.TalkGroupMapper;
import com.cf.game.group.model.TalkGroup;
import com.cf.game.group.vo.GroupVo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;

/**
 * boot-awm-GroupService
 *
 * @author <a href="2428922347@qq.com">Zhu mingming</a>
 * @info
 * @since 2018/6/28 上午 11:08
 */
public class GroupService extends AbsBaseService<TalkGroup, TalkGroupMapper> {

    @Autowired
    private GroupUserMapper groupUserMapper;

    private List<GroupVo> myGroup(long userId) {
        List<Long> groupIds = groupUserMapper.selectByUserId(userId);
        return this.selectByIds(groupIds).stream().map(g -> {
            return new GroupVo(g.getId(), g.getName());
        }).collect(Collectors.toList());
    }

    @Override
    public Class getTargetClass() {
        return TalkGroup.class;
    }

    public List<Long> getGroupUser(long groupId) {
        return groupUserMapper.selectByGroupId(groupId);
    }
}
